# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Ondřej Surý <ondrej@sury.org>
# Contributor: Julian Brost <julian@0x4a42.net>
# Contributor: Oleander Reis <oleander@oleander.cc>
# Contributor: Otto Sabart <seberm[at]gmail[dot]com>

pkgname=knot
pkgver=3.2.6
pkgrel=1
pkgdesc="High-performance authoritative-only DNS server"
arch=(loong64 x86_64)
url="https://www.knot-dns.cz/"
license=(GPL3)
depends=(libedit gnutls liburcu lmdb
         libidn2 systemd libcap-ng
         fstrm protobuf-c libmaxminddb
         libbpf libxdp libnghttp2 libmnl)
backup=('etc/knot/knot.conf')
source=("https://secure.nic.cz/files/knot-dns/${pkgname}-${pkgver}.tar.xz"{,.asc})
sha256sums=('ac124fb17dbc4ac5310a30a396245a6ba304b3c89abed0f8a47d727462c8da4d'
            'SKIP')
validpgpkeys=(742FA4E95829B6C5EAC6B85710BB7AF6FEBBD6AB) # Daniel Salzman <daniel.salzman@nic.cz>

build() {
    cd ${pkgname}-${pkgver}

    ./configure \
        --prefix=/usr \
        --sbindir=/usr/bin \
        --sysconfdir=/etc \
        --localstatedir=/var/lib \
        --libexecdir=/usr/lib/knot \
        --with-rundir=/run/knot \
        --with-storage=/var/lib/knot \
        --enable-dnstap \
        --enable-quic \
        --disable-silent-rules

    make
}

check() {
    cd ${pkgname}-${pkgver}
    make check
}

package() {
    cd ${pkgname}-${pkgver}

    make DESTDIR="${pkgdir}" install

    # Don’t keep those empty dir, manage them with systemd-tmpfiles instead
    rmdir "${pkgdir}"/{var/{lib/{knot/,},},run/{knot/,}}

    rm "${pkgdir}"/etc/knot/example.com.zone
    mv "${pkgdir}"/etc/knot/{knot.sample.conf,knot.conf}

    install -Dm644 distro/common/knot.service -t "${pkgdir}"/usr/lib/systemd/system/
    install -Dm644 distro/pkg/arch/knot.tmpfiles.arch "${pkgdir}"/usr/lib/tmpfiles.d/${pkgname}.conf
    install -Dm644 distro/pkg/arch/knot.sysusers "${pkgdir}"/usr/lib/sysusers.d/${pkgname}.conf
}
